﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BLO;
using DTO;
namespace QuanLyBanHang
{
    public partial class frmBaoCaoHDB : Form
    {
        public frmBaoCaoHDB()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmBaoCaoHDB_Load(object sender, EventArgs e)
        {
            Utility.ComboboxUlt.LoadData(new SanPham_Blo().GetAllObject(), cbbMH, new[] { "TenSP", "MaSP" }, "Chọn sản phẩm");
            cbbQuy.SelectedIndex = 0;
        }

        private void btnTim_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(cbbMH.SelectedValue.ToString()))
            {
                MessageBox.Show("Hãy chọn sản phẩm!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            LoadData();
        }

        private void LoadData()
        {
            int quy = int.Parse(cbbQuy.SelectedItem.ToString());
            string masp = cbbMH.SelectedValue.ToString();

            HoaDonBan_Blo hoaDonBanBlo = new HoaDonBan_Blo();
            dgvResult.DataSource = hoaDonBanBlo.GetHoaDonBans(masp, quy);

            if (dgvResult.DataSource == null) return;

            dgvResult.Columns["MaHDB"].HeaderText = "Mã HDB";
            dgvResult.Columns["NgayBan"].HeaderText = "Ngày bán";
            dgvResult.Columns["MaNV"].HeaderText = "Mã nhân viên";
            dgvResult.Columns["MaKH"].HeaderText = "Mã khách hàng";
            dgvResult.Columns["TongTien"].HeaderText = "Tổng tiền";
        }
    }   
}
